<?php
//No direct access
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');

class OwnserviceViewSettings extends JView
{
	function display($tpl = null) {

		global $mainframe;
		
		//Initialise variables
		$document	= & JFactory::getDocument();
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		$params 	= & $mainframe->getParams('com_ownservice');

		if($user->gid < 25) {
			if (!Ownservice::checkAccess( 'setting', 'manage' )) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect( 'index.php?option=com_ownservice');
			}
		}

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');

		// Get data form the model
		$model		= $this->getModel();
		$rows		= & $this->get('Data');

		// Create a user access object for the current user
		$access = new stdClass();
		$access->canEdit	= ($user->gid < 25)? Ownservice::checkAccess('setting','edit','setting','all'):1;


		$items = array();

		for($i=0,$n=count($rows);$i<$n;$i++) {
			$items[$rows[$i]->title] = $rows[$i]->value;
		}

		//set page title
		$params->set('page_title',	JText::_('OWNSERVICE_SETTINGS'));
		$document->setTitle( $params->get('page_title') );

		$lists = array();

		//build date format select list
		$datelist = array ();
		$datelist[] = JHTML :: _('select.option', "%A, %B %d, %Y", JHTML :: _('date', date("Y-m-d"), "%A, %B %d, %Y"));
		$datelist[] = JHTML :: _('select.option', "%d %B %Y", JHTML :: _('date', date("Y-m-d"), "%d %B %Y"));
		$datelist[] = JHTML :: _('select.option', "%B %d, %Y", JHTML :: _('date', date("Y-m-d"), "%B %d, %Y"));
		$datelist[] = JHTML :: _('select.option', "%d %B %Y", JHTML :: _('date', date("Y-m-d"), "%d %B %Y"));
		$datelist[] = JHTML :: _('select.option', "%d %B", JHTML :: _('date', date("Y-m-d"), "%d %B"));
		$datelist[] = JHTML :: _('select.option', "%d %b", JHTML :: _('date', date("Y-m-d"), "%d %b"));
		$datelist[] = JHTML :: _('select.option', "%d %b %Y", JHTML :: _('date', date("Y-m-d"), "%d %b %Y"));
		$datelist[] = JHTML :: _('select.option', "%m/%d/%y", JHTML :: _('date', date("Y-m-d"), "%m/%d/%y"));
		$datelist[] = JHTML :: _('select.option', "%d/%m/%y", JHTML :: _('date', date("Y-m-d"), "%d/%m/%y"));
		$datelist[] = JHTML :: _('select.option', "%m.%d.%y", JHTML :: _('date', date("Y-m-d"), "%m.%d.%y"));
		$datelist[] = JHTML :: _('select.option', "%d.%m.%y", JHTML :: _('date', date("Y-m-d"), "%d.%m.%y"));
		$datelist[] = JHTML :: _('select.option', "%m-%d-%y", JHTML :: _('date', date("Y-m-d"), "%m-%d-%y"));
		$datelist[] = JHTML :: _('select.option', "%d-%m-%y", JHTML :: _('date', date("Y-m-d"), "%d-%m-%y"));
		$datelist[] = JHTML :: _('select.option', "%m/%d/%Y", JHTML :: _('date', date("Y-m-d"), "%m/%d/%Y"));
		$datelist[] = JHTML :: _('select.option', "%d/%m/%Y", JHTML :: _('date', date("Y-m-d"), "%d/%m/%Y"));
		$datelist[] = JHTML :: _('select.option', "%m.%d.%Y", JHTML :: _('date', date("Y-m-d"), "%m.%d.%Y"));
		$datelist[] = JHTML :: _('select.option', "%d.%m.%Y", JHTML :: _('date', date("Y-m-d"), "%d.%m.%Y"));
		$datelist[] = JHTML :: _('select.option', "%m-%d-%Y", JHTML :: _('date', date("Y-m-d"), "%m-%d-%Y"));
		$datelist[] = JHTML :: _('select.option', "%d-%m-%Y", JHTML :: _('date', date("Y-m-d"), "%d-%m-%Y"));

		$lists['date_format'] = JHTML::_('select.genericlist', $datelist, 'setting[date_format]', 'class="inputbox"', 'value', 'text', $items['date_format'] );

		//build time format select list
		$timelist = array ();
		$timelist[] = JHTML :: _('select.option', "g:i:s a",'1:30:00 pm');
		$timelist[] = JHTML :: _('select.option', "g:i:s A", '1:30:00 PM');
		$timelist[] = JHTML :: _('select.option', "G:i:s", '9:30:00');
		$timelist[] = JHTML :: _('select.option', "h:i:s a", '01:30:00 pm');
		$timelist[] = JHTML :: _('select.option', "h:i:s A", '01:30:00 PM');
		$timelist[] = JHTML :: _('select.option', "H:i:s", '09:30:00');
	
		$lists['time_format'] = JHTML::_('select.genericlist', $timelist, 'setting[time_format]', 'class="inputbox"', 'value', 'text', $items['time_format'] );

		//build price format select list
		$pricelist = array();
		$pricelist[] = JHTML :: _('select.option', "#,###.##", JText :: _("#,###.##"));
		$pricelist[] = JHTML :: _('select.option', "#.###.##", JText :: _("#.###.##"));
		$pricelist[] = JHTML :: _('select.option', "#,###", JText :: _("#,###"));
		$pricelist[] = JHTML :: _('select.option', "#.###", JText :: _("#.###"));
		$pricelist[] = JHTML :: _('select.option', "####", JText :: _("####"));

		$lists['price_format'] = JHTML::_('select.genericlist', $pricelist, 'setting[price_format]', 'class="inputbox"', 'value', 'text', $items['price_format'] );

		$this->assignRef('items', $items);
		$this->assignRef('user', $user);
		$this->assignRef('ownuser', $ownuser);
		$this->assignRef('lists', $lists);
		$this->assignRef('user', $user);
		$this->assignRef('access', $access);

		parent::display($tpl);
	}
}